package com.zzyl.controller.customer;

import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.UserLoginRequestDto;
import com.zzyl.service.DeviceService;
import com.zzyl.service.MemberService;
import com.zzyl.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * <p>
 * 用户管理
 */
@Slf4j
@Api(tags = "客户管理")
@RestController
@RequestMapping("/customer/user")
public class CustomerUserController extends BaseController {

    @Autowired
    private MemberService memberService;

    /**
     * C端用户登录--微信登录
     *
     * @param userLoginRequestDto 用户登录信息
     * @return 登录结果
     */
    @PostMapping("/login")
    @ApiOperation("登录")
    public ResponseResult<LoginVo> login(@RequestBody UserLoginRequestDto userLoginRequestDto) throws IOException {
        LoginVo login = memberService.login(userLoginRequestDto);
        return success(login);
    }

    @Autowired
    DeviceService deviceService;


    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public ResponseResult QueryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) throws IOException {


        ResponseResult responseResult = deviceService.queryDevicePropertyStatus(deviceDto);


        return responseResult;
    }



//    functionId: HeartRate
//    startTime: 1716739200000
//    endTime: 1716825599999
//    iotId: nvZQpcCZVqD7zIq31XQhk1bok0

    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public ResponseResult queryDeviceDataListByDay(
            @ApiParam(value = "功能id", required = true) String functionId,
            @ApiParam(value = "开始时间", required = true) Long startTime,
            @ApiParam(value = "结束时间", required = true) Long endTime,
            @ApiParam(value = "设备id", required = true) String iotId ) throws IOException {
        log.info("functionId:{},startTime:{},endTime:{},iotId:{}",functionId,startTime,endTime,iotId);

       ResponseResult responseResult = deviceService.queryDeviceDataListByDay(iotId,functionId,startTime,endTime);

        return responseResult;
    }

    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public ResponseResult queryDeviceDataListByWeek(
            @ApiParam(value = "功能id", required = true) String functionId,
            @ApiParam(value = "开始时间", required = true) Long startTime,
            @ApiParam(value = "结束时间", required = true) Long endTime,
            @ApiParam(value = "设备id", required = true) String iotId ) throws IOException {
        log.info("functionId:{},startTime:{},endTime:{},iotId:{}",functionId,startTime,endTime,iotId);

        ResponseResult responseResult = deviceService.queryDeviceDataListByWeek(iotId,functionId,startTime,endTime);

        return responseResult;
    }



}
